﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeatherSystem.Net;

namespace WeatherSystem.Application.MsgHandler
{
    class EventHandler : IMsgHandler
    {
        public Message Handle(HttpArgs args)
        {
            if (args.GetPostValue()["ScanCodeInfo"] != null)
            {
                return new QrCodeEventMessage
                {
                    FromUserName = args.GetPostValue()["FromUserName"]["#cdata-section"].ToString(),
                    ToUserName = args.GetPostValue()["ToUserName"]["#cdata-section"].ToString(),
                    Event = args.GetPostValue()["Event"]["#cdata-section"].ToString(),
                    EventKey = args.GetPostValue()["EventKey"]["#cdata-section"].ToString(),
                    Type = args.GetPostValue()["ScanCodeInfo"]["ScanType"]["#cdata-section"].ToString(),
                    Result = args.GetPostValue()["ScanCodeInfo"]["ScanResult"]["#cdata-section"].ToString()
                };
            }
            return new EventMessage
            {
                FromUserName = args.GetPostValue()["FromUserName"]["#cdata-section"].ToString(),
                ToUserName = args.GetPostValue()["ToUserName"]["#cdata-section"].ToString(),
                Event = args.GetPostValue()["Event"]["#cdata-section"].ToString(),
                EventKey = args.GetPostValue()["EventKey"]["#cdata-section"].ToString()
            };
        }
    }
}
